String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function  loadCode()
{
   var  img =$("#img");
   img.attr("src","../register/yanzhengma.jsp?now="+new Date());
}
function  checkSumbit()
{
   var  email =$("#email");
  if(email.val().trim().length==0)
  {
     alert("请输入邮箱!");
     email.focus();
     return;
  }
  var  emailRegex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
  if(!emailRegex.test(email.val().trim()))
  {
     alert("输入邮箱格式错误!");
     email.focus();
     return;
  }
  
  $.ajax({
     type:'post',
     url:'../../member/checkEmail.action?email='+email.val().trim(),
     success:function(msg)
     {
         var a=eval('('+msg+')');
         if(!a['result'])
         {
            alert('输入的邮箱不存在!')
         }else{
               var  code = $("#code");
				  if(code.val().trim().length==0)
				  {
				     alert("请输入验证码!");
				     code.focus();
				     return;
				  }
				  $.ajax({
				     type:'post',
				     url:'../../member/checkCode.action?code='+code.val(),
				     success:function(msg)
				     {
				         var a=eval('('+msg+')');
				         if(!a['result'])
				         {
				            alert('验证码输入错误!')
				         }else
				         {
				                 $.ajax({
								     type:'post',
								     url:'../../member/resetPassword.action?email='+email.val().trim(),
								     success:function(msg)
								     {
								           var a=eval('('+msg+')');
									         if(a['result']=='0'){
									             alert('邮箱无效或不存在!');
									         }else if(a['result']=='1'){
									             alert('邮件发送成功，请登陆邮箱查收!');
									             window.location.href="../../";
									         }else if(a['result']=='2'){
									             alert('该账户尚未激活!');
									             window.location.href="../../";
									         }else{
									             alert('邮件发送失败!');
									         }
								     }
								     });
				         
				         
				         }
				     }
				  });
         
         }
     }
  });
   
}